<?php

namespace App\Models\Trip\TripOrderRefund;

use App\Models\Trip\TripOrderCosts\TripOrderCost;
use App\Trip\Traits\ModelDateTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

abstract class RefundDetail extends Model
{
    use HasFactory, ModelDateTrait;

    const RETURN_TICKET_OR_CHANGED_ORIGIN_ORDER_REFUND = 1;
    const TICKET_SERVICE_FEE_REFUND                    = 2;
    const SELECTED_SEATS_REFUND                        = 3;
    const INSURE_REFUND                                = 4;
    const TICKET_CHANGE_SERVICE_FEE_REFUND             = 5;
    const TICKET_PRICE_DIFF_FEE_REFUND                 = 6;
    const TASK_UPGRADE_LEVEL_FEE_REFUND                = 8;
    const TASK_EDIT_DIFF_FEE_REFUND                    = 9;

    const COST_MAP_REFUND_TYPE
        = [
            TripOrderCost::COST_TYPE_TICKET                      => self::RETURN_TICKET_OR_CHANGED_ORIGIN_ORDER_REFUND,
            TripOrderCost::COST_TYPE_TICKET_SERVICE_FEE          => self::TICKET_SERVICE_FEE_REFUND,
            TripOrderCost::COST_TYPE_SELECT_SEAT                 => self::SELECTED_SEATS_REFUND,
            TripOrderCost::COST_TYPE_INSURE                      => self::INSURE_REFUND,
            TripOrderCost::COST_TYPE_CHANGE_SERVICE_FEE          => self::TICKET_CHANGE_SERVICE_FEE_REFUND,
            TripOrderCost::COST_TYPE_SNAP_HIGH_LEVEL_SERVICE_FEE => self::TASK_UPGRADE_LEVEL_FEE_REFUND,
            TripOrderCost::COST_TYPE_SNAP_EDIT_TICKET_PRICE_DIFF => self::TASK_EDIT_DIFF_FEE_REFUND,
        ];

    const REFUND_TYPE_DESC
        = [
            self::RETURN_TICKET_OR_CHANGED_ORIGIN_ORDER_REFUND => "退票退款", // 退票退款或改签原单退款
            self::TICKET_SERVICE_FEE_REFUND                    => "购票手续费",
            self::SELECTED_SEATS_REFUND                        => "优选铺席",
            self::INSURE_REFUND                                => "保险费",
            self::TICKET_CHANGE_SERVICE_FEE_REFUND             => "改签手续费",
            self::TICKET_PRICE_DIFF_FEE_REFUND                 => "车票差价",
            self::TASK_UPGRADE_LEVEL_FEE_REFUND                => "购买高速抢票服务",
            self::TASK_EDIT_DIFF_FEE_REFUND                    => "编辑抢票坐席差价",
        ];

    static function getCostTypeToRefundDetailType(int $cost_type): int
    {
        return self::COST_MAP_REFUND_TYPE[$cost_type];
    }

    static function getTypeDesc(int $type): string
    {
        return self::REFUND_TYPE_DESC[$type];
    }

    abstract public function addMore(TripOrderRefund $refund, array $data);

    abstract public function addOne(TripOrderRefund $refund, array $data);

    public function refund()
    {
        return $this->belongsTo(TripOrderRefund::class, 'refund_sn', 'refund_sn');
    }
}